<?php global $curUser; ?>
<script>
    function validate(){
        var reply_content = document.forms[1].reply_content;
        var submit = true;
        if(reply_content.value === ""){
            document.forms[1].reply_content.previousSibling.style.color = 'red';
            submit = false;
        }else{
            document.forms[1].reply_content.previousSibling.style.color = 'black';
        }
        if(submit){
            document.forms[1].submit();
        }
    }
    
    $(document).on('click', 'a#add_like', function(e){
        var data = $(this).attr('data');
        var datas = data.split('_');
        if($('div.group.fav').attr('class') !== "group fav marked"){
            var pl = new SOAPClientParameters();
            pl.add("statusid", datas[0]);
            pl.add("userid", datas[1]);
            pl.add("datecreated", datas[2]);
            SOAPClient.invoke("/m/", "addLike", pl, true, callback_addLike);
        }else{
            var pl = new SOAPClientParameters();
            pl.add("statusid", datas[0]);
            pl.add("userid", datas[1]);
            SOAPClient.invoke("/m/", "deleteLike", pl, true, callback_deleteLike);
        }
    });
    
    function callback_deleteLike(r){
        if(r === "true"){
            $('a#add_like span').text("Like?");
            $('a#add_like').attr('class', 'meta-act-link meta-like fav-toggle');
            $('div.group.fav').attr('class', 'group fav');
            var datas = $('a#add_like').attr('data').split("_");
            var pl = new SOAPClientParameters();
            pl.add("statusid", datas[0]);
            SOAPClient.invoke("/m/", "getAmountLike", pl, true, callback_getAmountLike);
        }
    }
    
    function callback_addLike(r){
        if(r !== 0){
            var datas = $('a#add_like').attr('data').split("_");
            var pl = new SOAPClientParameters();
            pl.add("statusid", datas[0]);
            SOAPClient.invoke("/m/", "getAmountLike", pl, true, callback_getAmountLike);
            $('a#add_like span').text("You Like");
            $('a#add_like').attr('class', 'current-user-likes meta-act-link fav-toggle');
            $('div.group.fav').attr('class', 'group fav marked');
        }
    }
    
    function callback_getAmountLike(r){
        if(r !== -1){
            if(r === 1){
                $('a#amount_like').text(r + " like");
            }else{
                $('a#amount_like').text(r + " likes");
            }
        }
    }
</script>
<?php if($this->images == ""){ ?>
<ul class="tabs">
    <li <?php if (strtoupper($this->params[1]) == 'POPULAR') echo 'class="active"' ?>>
        <a href="<?php echo $this->baseUrl ?>Shots/Popular?page=1">Popular</a>
    </li>
    <li <?php if (strtoupper($this->params[1]) == 'EVERYONE') echo 'class="active"' ?>>
        <a href="<?php echo $this->baseUrl ?>Shots/Everyone?page=1">Everyone</a>
    </li>
    <li <?php if (strtoupper($this->params[1]) == 'DEBUTS') echo 'class="active"' ?>>
        <a href="<?php echo $this->baseUrl ?>Shots/Debuts?page=1">Debuts</a>
    </li>
</ul>
<div class="null-message">
      <h2>You aren’t following anyone yet.</h2>
      <p>
        Explore the links above to discover shots and players.
        <br>
        The latest shots from players you follow will appear here.
      </p>
</div>
<?php }else{ 
    $photo = Photo::withEncode($this->images);
    $status = Status::withId(Status::getStatusId($photo->id));
    $user = User::withId(User::getUserId(Status::getStatusId($photo->id)));
    $avatar = Photo::withId($user->avatarid);
    if($_POST['reply']){
        $reply = Reply::withData($status->id, $user->id, $_POST['reply']['content'], date("Y-m-d"));
        Reply::addReply($reply);
        echo '<script>parent.window.location.reload(true);</script>';
    }
    Status::increaseView($status->id);
    $status = Status::withId(Status::getStatusId($photo->id));
    $replies = Reply::getReplies($status->id);
    $arr_reply = explode(";", $replies);
?>
<div id="main">
  <div id="screenshot-title-section" class="full title">
    <div class="single-title vcard group">
      <a href="<?php echo $this->baseUrl.$user->username; ?>" class="url" rel="contact" title="<?php echo $user->username; ?>"><div data-picture="" data-alt="<?php echo $user->username; ?>" data-class="photo">
  <div data-src="<?php echo $this->baseUrl.$avatar->url; ?>"></div>
  <div data-src="<?php echo $this->baseUrl.$avatar->url; ?>" data-media="(-webkit-min-device-pixel-ratio: 1.5),
       (min--moz-device-pixel-ratio: 1.5),
       (-o-min-device-pixel-ratio: 3/2),
       (min-device-pixel-ratio: 1.5),
       (min-resolution: 1.5dppx)"></div>
<img alt="<?php echo $user->username; ?>" class="photo" src="<?php echo $this->baseUrl.$avatar->url; ?>"></div>
</a>
      <h1 id="screenshot-title"><?php echo $photo->title; ?></h1>
      <div class="shot-byline">
        <div class="attribution ">
          <span class="shot-byline-user">
            by <a href="" class="url" rel="contact"><?php echo $user->username; ?></a>
          </span>
          <div class="follow-prompt">
                <a href="/yoga/followers" class="follow">
                <span>Follow</span>
                </a><a href="/yoga/followers/yoga" class="unfollow">
                    <span>Following</span>
                </a><a href="/blocks/yoga" class="unblock" data-hover="Unblock">Blocked</a>
            </div>
        </div>
        <span class="screenshot-dash">
          <?php echo date("D M-d-Y", strtotime($status->datecreated)); ?>
        </span>
      </div>
    </div>
  </div>

<div class="the-shot" data-screenshot_id="1345706">
  <div class="single">
    <div class="single-grid"><div class="single-img">
      <div data-picture="" data-alt="<?php echo $photo->title; ?>">
        <div data-src="<?php echo $this->bseUrl.$photo->url; ?>"></div>
        <div data-src="<?php echo $this->bseUrl.$photo->url; ?>" data-media="(-webkit-min-device-pixel-ratio: 1.5),
            (min--moz-device-pixel-ratio: 1.5),
            (-o-min-device-pixel-ratio: 3/2),
            (min-device-pixel-ratio: 1.5),
            (min-resolution: 1.5dppx)"></div>
             <img alt="<?php echo $photo->title; ?>" src="<?php echo $this->baseUrl.$photo->url; ?>">
      </div>
    </div></div>
  </div>
</div>

  <div class="screenshot-meta">
    <div id="like-section" class="meta-act logged-in">
        <div class="group fav <?php if(Like::checkLike($status->id, $user->id)) echo "marked"; ?>">
    <strong class="fav-number">
      <a id="amount_like"><?php
        $amount = Like::getAmountLike($status->id);
        if($amount != -1){
            if($amount == 1 || $amount == 0) 
                echo $amount." like";
            else
                echo $amount." likes";
        }
      ?></a>
    </strong>
    <a id="add_like" data="<?php echo $status->id."_".$curUser->id."_".date("Y-m-d"); ?>" class="<?php if(Like::checkLike($status->id, $user->id)) echo "current-user-likes meta-act-link fav-toggle"; else echo "meta-act-link meta-like fav-toggle"; ?>" title="<?php if(Like::checkLike($status->id, $user->id)) echo "You like this screenshot. Click to undo."; else echo "Like this screenshot?"; ?>">
      <span><?php if(Like::checkLike($status->id, $user->id)) echo "You Like"; else echo "Like?"; ?></span>
</a></div>
</div>
<div class="meta-act meta-act-views">
  <span class="meta-act-link meta-views"><?php echo $status->view; ?> <em>views</em></span>
</div>
      
<div class="social-media meta-act meta-act-full">
  <a href="#" class="meta-act-link meta-share">Share</a>
  <div id="share-links">
    <div class="group">
      <div id="share-button-twitter" class="meta-share-wrap">
        <span class="share-icons share-icon-twitter"></span><span class="shot-social-count">5</span>
      </div>
      <div id="share-button-fb" class="meta-share-wrap">
        <span class="share-icons share-icon-fb"></span><span class="shot-social-count">0</span>
      </div>
      <div id="share-button-pin" class="meta-share-wrap">
        <span class="share-icons share-icon-pin"></span><span class="shot-social-count">136</span>
      </div>
    </div>
    <div class="meta-link">
      <input type="url" id="share-form-url" value="http://drbl.in/jDIY" readonly="">
      <a id="meta-short-url" href="http://drbl.in/jDIY" class="meta-link-text">http://drbl.in/jDIY</a>
    </div>
  </div>
</div>
<div class="meta-act meta-act-full">
        <div class="meta-act-link meta-colors">
            <ul class="color-chips group">
                <?php 
                    echo Color::getColorBarNotDefault($photo->url);
                ?>
            </ul>
        </div>
      </div>
  </div>
  <div id="comments-section">
  <h2 class="count section ">
    <?php echo $status->replies; ?> Responses
  </h2>

    <ol id="comments" class="comments">
      <?php 
        for($i = 0; $i < sizeof($arr_reply) - 1; $i++){
            $reply = Reply::withId($arr_reply[$i]);
            $user_reply = User::withId($reply->userid);
            $avatar_reply = Photo::withId($user_reply->avatarid);
            $result = '<li id="comment-3189966" class="response comment group " data-user-id="23085">
                        <h2>
                        <a href="'.$this->baseUrl.$user_reply->username.'" class="url" rel="contact" title="'.$user_reply->username.'"><img alt="'.$user_reply->username.'" class="photo" src="'.$this->baseUrl.$avatar_reply->url.'"> '.$user_reply->username.'</a>
                        </h2>
                        <div class="comment-body">
                        <p>'.$reply->content.'</p>
                        </div>
                        <span class="comment-meta-likes">
                        <a href="/comments/3189966/likes" class="likes-list">6</a><span class="hide">likes</span>
                        </span>
                        <p class="comment-meta">
                        <a href="#comment-3189966" class="posted">'.date("D M-d-Y", strtotime($reply->datecreated)).'</a>
                        <span class="sep">|</span>
                        <a href="/comments/3189966/likes" class="likes">Like?</a>
                        </p>
                        </li>';
            echo $result;
        }
      ?>
  </ol>
    <form onsubmit="return false;" accept-charset="UTF-8" action="<?php echo $this->baseUrl; ?>Shots/<?php echo $photo->encode; ?>" class="account gen-form with-messages" id="upload_photo" method="post" style="float: left; width: 450px;"> 
        <div class="form-field form-field-bio">
            <fieldset class="reply_content"><label for="reply_content" style="width: 70px;">Content</label><textarea class="bio" cols="40" id="reply_content" name="reply[content]" rows="3" style="resize: none; width: 320px;" maxlength="160"></textarea></fieldset>
        </div>
        <div class="form-btns">
            <input style="margin-left: 50px;" class="form-sub" name="reply" type="submit" value="Reply" onclick="validate();">
        </div>
    </form>
</div>
</div>
<?php } ?>
